//
//  CommonAddressViewModel.m
//  didacar
//
//  Created by 度周末网络-王腾 on 15/12/14.
//  Copyright © 2015年 dzmmac. All rights reserved.
//

#import "CommonAddressViewModel.h"
#import "PoisModel.h"

@implementation CommonAddressViewModel

-(id)init{
    self.titleList = @[@[@"家庭住址",@"公司地址"],@[@"上班时间",@"下班时间"]];
    self.homePoisModel = [[PoisModel alloc ] init];
    self.companyPoisModel = [[PoisModel alloc ] init];
    return [super init];
}

-(void)addAddess:(DealDataResultBlock)reslutBlock{
    
    NSMutableDictionary *postData = [[NSMutableDictionary alloc ] init];
    
    [postData setObj:USERINFOManager.getUserInfo.MemberId forKey:@"MemberId"];
    
    // 家庭地址
    [postData setObj:self.homePoisModel.name forKey:@"MyHomeAddress"];
    
    // 家庭地址经度
    [postData setObj:@(self.homePoisModel.longitude).stringValue forKey:@"MyHomeLng"];
    
    // 家庭地址纬度
    [postData setObj:@(self.homePoisModel.latitude).stringValue forKey:@"MyHomeLat"];
    
    // 工作地址
    [postData setObj:self.companyPoisModel.name forKey:@"MyWorkAddress"];
    
    // 工作地址经度
    [postData setObj:@(self.companyPoisModel.longitude).stringValue forKey:@"MyWorkLng"];
    
    // 工作地址纬度
    [postData setObj:@(self.companyPoisModel.latitude).stringValue forKey:@"MyWorkLat"];
    
    // 上班时间
    [postData setObj:self.startTime forKey:@"MyGoWorkTime"];
    
    // 下班时间
    [postData setObj:self.endTime forKey:@"MyOffWorkTime"];


    [[BaseHttpRequest sharedInstance] sendRequestToPost:AddAddress withData:postData alertMessage:@"" success:^(NSDictionary *dicData) {
        reslutBlock(1,nil,nil);
        
        [CommonAddressViewModel getMyAddress:^(NSInteger resultType, id data, NSString *errorMsg) {
            
        }];
    } error:^(NSString *errorMsg) {
        reslutBlock(0,nil,errorMsg);
    }];
}


+(void)getMyAddress:(DealDataResultBlock)resultBlock{
    NSMutableDictionary *postData = [[NSMutableDictionary alloc ] init];
    
    [postData setObj:USERINFOManager.getUserInfo.MemberId forKey:@"MemberId"];
    
    if (postData.allValues.count == 0) {
        return;
    }
    
    [[BaseHttpRequest sharedInstance] sendRequestToPost:GetMyAddress withData:postData alertMessage:nil success:^(NSDictionary *dicData) {
        
        [[NSUserDefaults standardUserDefaults]setObject:dicData forKey:@"MyAddress"];
        resultBlock(1,nil,nil);
        
    } error:^(NSString *errorMsg) {
        resultBlock(0,nil,errorMsg);
    }];
}

@end
